package com.heng.atomics;

import java.util.concurrent.CountDownLatch;

class BankAccout{//资源类
    String bankName = "CCB";
    int money = 0;

    public synchronized void add(){//百分百线程安全
        money++;
    }
}

public class XXXAtomicIntegerFieldUpdaterDemo4 {
    public static void main(String[] args) throws InterruptedException {
        BankAccout bankAccout = new BankAccout();
        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 1;i<=10 ;i++) {
            new Thread(()->{
                try{
                    for(int j = 1; j<= 1000;j++) {
                        bankAccout.add();
                    }
                }finally {
                    countDownLatch.countDown();
                }
            },String.valueOf(i)).start();
        }

        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"\tresult:"+bankAccout.money);

    }
}
